package config

import "github.com/gin-gonic/gin"

type (
	Environment string
)

const (
	// EnvProd 生产环境
	EnvProd Environment = "prod"
	// EnvTest 集成测试环境
	EnvTest Environment = "test"
	// EnvDev 开发机环境
	EnvDev Environment = "dev"
	// EnvLocal 本机电脑
	EnvLocal Environment = "local"
)

func (e Environment) String() string {
	return string(e)
}

// GetEnvironmentByStr 根据环境字符串获取环境枚举
func GetEnvironmentByStr(envStr string) Environment {
	switch envStr {
	case EnvLocal.String():
		return EnvLocal
	case EnvTest.String():
		return EnvTest
	case EnvDev.String():
		return EnvDev
	default:
		return EnvProd
	}
}

// GetGinModeByEnv 根据环境获取GIN_MODE
func GetGinModeByEnv(env Environment) string {
	switch env {
	case EnvLocal:
		return gin.DebugMode
	case EnvDev:
		return gin.DebugMode
	case EnvTest:
		return gin.TestMode
	default:
		return gin.ReleaseMode
	}
}

// GetEnvConfFilename 根据环境获获取文件名
func GetEnvConfFilename(env Environment) string {
	if len(env) == 0 {
		return ""
	}
	return "settings." + env.String() + ".toml"
}
